package com.ztc.ZtcWalletLog.dao;

import com.aqgj.util.BaseDaoImpl;
import com.aqgj.util.Pager;
import com.ztc.ZtcWalletLog.bean.ZtcWalletLog;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 *
 */
@Repository("ZtcWalletLogDao")
public class ZtcWalletLogDao extends BaseDaoImpl<ZtcWalletLog> {

    /** 获取app用户收支明细 */
    public Pager<HashMap<String,Object>> getZtcWalletLogByAccount(String uid, Integer pageNumber, Integer pageSize,String startTime,String endTime) {
        Pager<HashMap<String,Object>> pager=new Pager<>();
        pager.setPageSize(pageSize);
        pager.setCurrentPage(pageNumber);
        String sql="select id,fk_user_id,type,money,after_balance,fk_order_id,comment,from_unixtime(add_time/1000) add_time from ztc_wallet_log where 1=1 ";
        if(uid!=null){
            sql+=" and fk_user_id='"+uid+"' ";
        }
        if(startTime!=null&&!"".equals(startTime)&&endTime!=null&&!"".equals(endTime)){
            sql+="and (from_unixtime(add_time/1000)>='"+startTime+"' and from_unixtime(add_time/1000)<='"+endTime+"') ";
        }
        sql+=" order by add_time desc";
        HashMap<String,Object> map= this.listAndSumSqlPagQuery(sql,pageNumber,pageSize);
        pager.setRecordTotal(Integer.parseInt(map.get("sum").toString()));
        String [] stringArrays=new String[]{"id","fkUserId","type","money","afterBalance","fkOrderId","comment","addTime"};
        pager.setContent(this.getKeyList((List<Object[]>) map.get("data"),stringArrays));
        return pager;
    }

    public List<ZtcWalletLog> getWalletLogByOrderIdAndType(String orderId,Set<Integer> integerSet){
        String sql="select * from ztc_wallet_log where fk_order_id = ? and type in (:typeList)";
        return this.currentSession().createNativeQuery(sql,ZtcWalletLog.class).setParameter(1,orderId).setParameterList("typeList",integerSet).getResultList();
    }

}